//
//  WTAnimationOperation.m
//  66TV
//
//  Created by ben on 16/8/4.
//  Copyright © 2016年 shifeng. All rights reserved.
//

#import "WTAnimationOperation.h"


@interface WTAnimationOperation ()
@property (nonatomic, getter = isFinished)  BOOL finished;
@property (nonatomic, getter = isExecuting) BOOL executing;
@property (nonatomic,copy) void(^finishedBlock)(BOOL result,NSInteger finishCount);
@property (nonatomic, strong) WTChatRoomGiftModel*      giftModel;
@end

@implementation WTAnimationOperation
@synthesize finished = _finished;
@synthesize executing = _executing;


+ (instancetype)animOperation:(WTChatRoomGiftModel *)model finishedBlock:(void (^)(BOOL, NSInteger))finishedBlock{
    
    WTAnimationOperation* op = [[WTAnimationOperation alloc] init];
    op.giftModel  = model;
    op.finishedBlock = finishedBlock;
    return op;
}

- (instancetype)init{
    
    self = [super init];
    if (self) {
        _executing = NO;
        _finished  = NO;
    }
    return self;
}

- (void)main{
    
}

- (void)start{
    
    if ([self isCancelled]) {
        self.finished = YES;
        return;
    }
    self.executing = YES;
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        self.giftShowView.giftModel = self.giftModel;
        [self.giftContainerView addSubview:self.giftShowView];
        [self.giftShowView animateWithCompleteBlock:^(BOOL finished, NSInteger finishCount) {
            self.finished = finished;
            self.finishedBlock(finished,finishCount);
        }];
    });
}
#pragma mark -  手动触发 KVO
- (void)setExecuting:(BOOL)executing
{
    [self willChangeValueForKey:@"isExecuting"];
    _executing = executing;
    [self didChangeValueForKey:@"isExecuting"];
}

- (void)setFinished:(BOOL)finished
{
    [self willChangeValueForKey:@"isFinished"];
    _finished = finished;
    [self didChangeValueForKey:@"isFinished"];
}
@end
